package com.yanqu.road.dao.impl.activity.snowgarden;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.snowgarden.config.SnowGardenCombConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SnowGardenCombConfigDaoImpl extends TempDao {

    private static String getSnowGardenCombConfigSql = "select * from `t_s_activity_snowgarden_comb` where `activityId`=?";

    public Map<Integer, SnowGardenCombConfig> getSnowGardenCombConfig(int activityId){
        Map<Integer, SnowGardenCombConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSnowGardenCombConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SnowGardenCombConfig snowGardenCombConfig = new SnowGardenCombConfig();
                snowGardenCombConfig.setActivityId(rs.getInt("activityId"));
                int id = rs.getInt("id");
                snowGardenCombConfig.setId(id);
                snowGardenCombConfig.setComb(rs.getInt("comb"));
                snowGardenCombConfig.setPeriod(rs.getInt("period"));
                snowGardenCombConfig.setName(rs.getString("name"));
                snowGardenCombConfig.setDesc(rs.getString("desc"));
                snowGardenCombConfig.setEffectDesc(rs.getString("effectDesc"));
                snowGardenCombConfig.setParam(rs.getInt("param"));
                snowGardenCombConfig.setReward(rs.getString("reward"));
                map.put(id, snowGardenCombConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
